
import 'package:daily/protocol_dialog.dart';
import 'package:flutter/material.dart';

import 'dart:convert' as convert;


import 'local_storage.dart';
import 'main.dart';

class Splash extends StatefulWidget {
  const Splash({super.key});

  @override
  State<Splash> createState() => _SplashState();
}

class _SplashState extends State<Splash> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        color: Colors.white,
      ),
    );
  }

  @override
  void initState() {
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      _pushMainPage();
    });
    super.initState();
  }

  _pushMainPage() async {
    await LocalStorage.initSP();
    // await HttpDNSManager.openProxy();
    var isInstalled = LocalStorage.get('isInstalled');
    // 已安装并同意进入app
    if (isInstalled == '1') {
      // ignore: use_build_context_synchronously
      Navigator.pushAndRemoveUntil(
          context,
          MaterialPageRoute(builder: (context) =>  MyHomePage()),
              (route) => false);
      // } else {
      //   // ignore: use_build_context_synchronously
      //   Navigator.pushAndRemoveUntil(
      //       context,
      //       MaterialPageRoute(builder: (context) => const LoginRegistePage(false)),
      //       (route) => false);
      // }
    } else {
      // ignore: use_build_context_synchronously
      ProtocolDialog.showProtocolDialog(context);
    }
  }



}
